<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ include file="/WEB-INF/jsp/commons/taglibs.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>E-天下商旅</title>
<link href="${ctx}/resources/css/page_financial.css" rel="stylesheet" type="text/css">
</head>
<script src="${ctx}/resources/script/validate/jquery-1.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){		 
	$("#js_tab_box1").load("${ctx}/transin/loadTransinData?timestap="+(new Date()).valueOf());	
	$("#js_tab_box2").load("${ctx}/transin//loadTransoutData?timestap="+(new Date()).valueOf());	
});

/**
 * 跳转页面
 */
function goPage(pageNo){	
	  var class_c = $("#js_tab1").attr("class");
	  if("current" == class_c){
		  $("#js_tab_box1").load("${ctx}/transin/loadTransinData?pageNo="+pageNo+"&timestap="+(new Date()).valueOf());
	  }else{
		  $("#js_tab_box2").load("${ctx}/transin/loadTransoutData?pageNo="+pageNo+"&timestap="+(new Date()).valueOf());
	  }
	
	
}

</script>
<body>


<jsp:include page="../commons/header.jsp" >
	 <jsp:param name="currentMenu" value="menu4"/>
</jsp:include>



<div class="main_box">
<div class="main cf">

	<jsp:include page="../commons/left.jsp"></jsp:include>
	<div class="right">
		<div class="right_box">
			<div class="title"><span><a href="#">转账管理</a></span></div>
			<div class="content cf">
				<div class="transfer_box">
					<div class="transfer_top">
						<div class="transfer_top_title cf"><a id="js_tab3" href="#" class="current">转积分到消费账户</a><a id="js_tab4" href="#">其它会员现金账户</a></div>
						<div id="js_tab_box3">
							<form id="consumptionForm" name="consumptionForm" action="" novalidate onsubmit="">
							    <div>
									<label>现金账户余额</label>
									<fmt:formatNumber value="${memberWallet.walletRemain}" pattern="##.##" minFractionDigits="2" ></fmt:formatNumber> 元									
					            </div>
					            <div>
									<label style="color:red">消费账户余额</label>
									<fmt:formatNumber value="${memberShopWallet.shopWalletBalance}" pattern="##.##" minFractionDigits="2" ></fmt:formatNumber> 元									
					            </div>
								<div>
									<label>转账金额</label>
									<input type="text" class="input" name="cMoney" id="cMoney" ><span></span>
									<input name="userCoAccount" id="userCoAccount" value="${memberWallet.baseUsername.baseUsername }" type="hidden" />
								</div>
								<div>
									<label>&nbsp;</label>
									<input type="submit" onclick="submitConsumptionForm();" class="submit btn_orange" value="提交" />
								</div>
							</form>
						</div>
						<div id="js_tab_box4">
							<form id="cashForm" name="cashForm" novalidate onsubmit="">
							    <div>
									<label>账户余额</label>
									<fmt:formatNumber value="${memberWallet.walletRemain}" pattern="##.##" minFractionDigits="2" ></fmt:formatNumber>  元									
					            </div>
								<div>
									<label>转入会员</label>
									<input type="text" id="targetAccount" name="targetAccount" class="input" ><span></span>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" id="js_choose_a" title="验证转入会员">验证</a><span id="js_choose_c"></span>
								</div>
								<div>
									<label>转账金额</label>
									<input type="text" name="cashMoney" id="cashMoney" class="input" ><span></span>
									<input name="userAccount" id="userAccount" value="${memberWallet.baseUsername.baseUsername }" type="hidden" />
								</div>
								<div>
									<label>&nbsp;</label>
									<input type="submit" class="submit btn_orange" value="提交" />
								</div>
							</form>
						</div>
					</div>
					<div class="transfer_bottom">
						<div class="transfer_bottom_title cf"><a href="#" id="js_tab1" class="current">转入数据查询</a><a href="#" id="js_tab2" class="">转出数据查询</a></div>
						<div id="js_tab_box1">
							<!-- 内容 -->
						</div>
						<div id="js_tab_box2">
							<!-- 内容 -->
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
		
</div>
</div>

<jsp:include page="../commons/footer.jsp"></jsp:include>



<script src="${ctx}/resources/script/common.js"></script>
<script type="text/javascript" src="${ctx}/resources/script/validate/jquery.validate.js"></script>
<script type="text/javascript" src="${ctx}/resources/script/validate/jquery.metadata.js"></script>
<script type="text/javascript" src="${ctx}/resources/script/validate/additional-methods.js" charset="utf-8"></script>
<script type="text/javascript" src="${ctx}/resources/script/validate/messages_cn.js" charset="utf-8"></script>
<script>
$(function(){

    $("#js_tab3").click(function(e) {    	
        if($(this).hasClass("current")) {
            return false;
        } else {
            $("#js_tab_box4").hide();
            $("#js_tab_box3").show();
            $(this).addClass("current");
            $("#js_tab4").removeClass("current");
        }
        return false;
    });
    
    $("#js_tab4").click(function(e) {
    	
        if($(this).hasClass("current")) {
            return false;
        } else {
            $("#js_tab_box3").hide();
            $("#js_tab_box4").show();
            $(this).addClass("current");
            $("#js_tab3").removeClass("current");
        }
        return false;
    });  
   

     function submitConsumptionForm(){     	
   		 	var url = "${ctx}/mW/transferOfConsume?timestap="+(new Date()).valueOf();
   		     $.ajax({
   		         type: "post",
   		         async:false,
   		         url: url,
   		         dataType: "json",
   		         data:$("#consumptionForm").serialize(),
   		         success: function(getmsg){  		            
   		         	 alert(getmsg.context);	
   		         	 window.location.href="${ctx}/financial/transfer?timestap="+(new Date()).getTime();
   		         }
   		     });
   	 }
     
     function submitCashForm(){     	
		 	var url = "${ctx}/mW/transferOfCash?timestap="+(new Date()).valueOf();
		     $.ajax({
		         type: "post",
		         async:false,
		         url: url,
		         dataType: "json",
		         data:$("#cashForm").serialize(),
		         success: function(getmsg){  		            
		         	 alert(getmsg.context);	
		         	 window.location.href="${ctx}/financial/transfer?timestap="+(new Date()).getTime();
		         }
		     });
	 }
     
     $.validator.addMethod("sizeV", function(value, element) {
			var reg = /^(([1-9])|([1-9][0-9]{1,}))$/;
			return this.optional(element) || (reg.test(value));
	 }, "转账金额必须为大于零的整数");

   
   	$("#consumptionForm").validate({
   		rules : {
   			cMoney:{
   				required : true,
   				sizeV:"",
   				remote:{
   					url: "${ctx}/mW/vftBalance", //后台处理程序    
   			        type:"post",
   			        dataType: "json",       				 //接受数据格式      
   			        data:  {                     			 //要传递的数据   
   			        	balance: function() {   
   			        				return $("#cMoney").val();   
   			        	  		  },
   			            userAccount:function(){
   			            	return $("#userCoAccount").val();   
   			            }
   			        } 
   				}
   			}
   		},
   		submitHandler:function(form){
   			submitConsumptionForm();
   		},
   		errorPlacement : function(error, element) {
   			error.appendTo(element.next("span"));
   		},
   		messages : {
   			cMoney:{
   				requried:"转账金额不能为空",   			
   				remote:"电子钱包余额不足"
   			}
   		}
   	 });
   	
	$("#cashForm").validate({
   		rules : {
   			cashMoney:{
   				required : true,
   				sizeV:"",
   				remote:{
   					url: "${ctx}/mW/vftBalance", //后台处理程序    
   			        type:"post",
   			        dataType: "json",       				 //接受数据格式      
   			        data:  {                     			 //要传递的数据   
   			        	balance: function() {   
   			        				return $("#cashMoney").val();   
   			        	  		  },
   			            userAccount:function(){
   			            	return $("#userAccount").val();   
   			            }
   			        } 
   				}
   			},
   			targetAccount:{
   				required : true,
   				remote:{
   					url: "${ctx}/mW/vftAccount", //后台处理程序    
   			        type:"post",
   			        dataType: "json",       				 //接受数据格式      
   			        data:  {                  			 //要传递的数据      			        	
   			            userAccount:function(){   			            
   			            	return $("#targetAccount").val();   
   			            }
   			        } 
   				}
   			}
   		},
   		submitHandler:function(form){
   			submitCashForm();
   		},
   		errorPlacement : function(error, element) {
   			error.appendTo(element.next("span"));
   		},
   		messages : {
   			cashMoney:{
   				requried:"转账金额不能为空",   			
   				remote:"电子钱包余额不足"
   			},
   			targetAccount:{
   				requried:"转入会员不能够为空", 
   				remote:"输入会员不存在或未激活"
   			}
   		}
   	 });
	
	$("#js_choose_a").click(function(e){
		
		var url = "${ctx}/mW/checkUserAccount?timestap="+(new Date()).valueOf();		
	     $.ajax({
	         type: "post",
	         async:false,
	         url: url,
	         dataType: "json",
	         data:$("#cashForm").serialize(),
	         success: function(getmsg){  	        	 
	        	 $("#js_choose_c").text(getmsg.context);
	         	         	 
	         }
	     });
	});
})
</script>
</body>
</html>
